/**
 * 
 */
package edu.hm.compiler.parser.grammar.term;

import edu.hm.compiler.parser.grammar.ConstantString;
import edu.hm.compiler.parser.grammar.variable.Variable;

/**
 * @author Saruman
 */
public class TermString implements Term
{
    private final ConstantString constantString;

    /**
     * @param constantString
     */
    public TermString( final ConstantString constantString )
    {
        this.constantString = constantString;
    }

    public ConstantString getConstantString()
    {
        return this.constantString;
    }

    @Override
    public String toString()
    {
        return "TermString [constantString=" + this.constantString + "]"; //$NON-NLS-1$ //$NON-NLS-2$
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = 1;
        result = prime * result + ( ( this.constantString == null ) ? 0 : this.constantString.hashCode() );
        return result;
    }

    /*
     * (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals( final Object obj )
    {
        if( this == obj )
            return true;
        if( obj == null )
            return false;
        if( obj instanceof Variable )
            return true;
        if( this.getClass() != obj.getClass() )
            return false;
        final TermString other = (TermString) obj;
        if( this.constantString == null )
        {
            if( other.constantString != null )
                return false;
        } else if( !this.constantString.equals( other.constantString ) )
            return false;
        return true;
    }

    @Override
    public String getString()
    {
        final String string = this.constantString.getString();
        return string.substring( 1, string.length() - 1 );
    }
}
